# Makefile for making GDS/CIF/EGS files up to the suffix of the designated file.
# Normally you only need to supply a C++ source file (e.g. myfile.cc) and
# add the corresponding name of the GDS file in the variable below (e.g.
# myfile.gds).
# Typing 'make' (from appropriate directory in shell) should compile and run the program, 
# producing the GDS file.
# Typing 'make clean' should remove all cif files and all executables and
# backup files.
#
# Xaveer Leijtens 04/03/22
# Yongbo Tang 2012/10/24


# Enter the basename of your input <BaseName>.cc and output <BaseName>.gds
OUTPUT	      = test_mask.gds
#               You can put more than one file here, separated by a space.

PROG	      = $(basename $(notdir $(OUTPUT)))
SUF         = $(suffix $(OUTPUT))
SUF2        = $(subst ., ,$(SUF))

CUSTOMOBJDIR = ../plug_in
SRCDIR = ../src

# path to libmask files here
# currently set for folder libmask, which should be in the parent directory
CXXFLAGS      = -s -I$(SRCDIR) -I$(CUSTOMOBJDIR)
LDFLAGS       = -L$(SRCDIR)

LIBS          = -lMask

CXX	      = g++
LD	      = g++

all:		objs $(OUTPUT)

clean:		
		rm -f $(OUTPUT) $(PROG) *~ *.bak *.gds *.exe *.stackdump
		cd $(SRCDIR); make clean;
		cd $(CUSTOMOBJDIR); make clean; 

$(OUTPUT): 	%$(SUF): %
		@echo "Executing to make $(SUF) file $@ ..."
#		./$< 2>&1 1> $@ 
#		./$< 1> $@
		./$< 
		@echo "done executing."

$(PROG):	%: %.cc %.h Makefile $(CUSTOMOBJDIR) $(SRCDIR)/*.a
		@echo "Compiling $< ..."
		$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(CUSTOMOBJDIR)/*.o $(LIBS)
		@echo "done compiling."
	
objs:
	cd $(SRCDIR); make;
	cd $(CUSTOMOBJDIR); make;

